<?php use Model\productModel;
    use Controller\Controller;

    class productController extends Controller {
        private $PRODUCT;

        public function __construct() {
            $this->PRODUCT = new productModel();
        }

        public function getAction($params = null) {
            $response = [];
            if ($this->request()["method"] !== "GET") {
                $this->errorJsonDie(400);
            }
            if ($params === null) {
                $response = $this->PRODUCT->getAllProduct();
            } else {
                $response = $this->PRODUCT->getProductById((int) $params);
            }
            $this->successJson($response);
        }
        public function addAction() {
            $request = $this->request();
            $json = $this->request()["json"];
            $response = [];
            if ($this->request()["method"] !== "POST") {
                $this->errorJsonDie(400);
            }
            if (!$json["title"] && !$json["description"] && !is_integer($json["price"])){
                $this->errorJsonDie(400);
            }
            $response = $this->PRODUCT->addProduct($json["title"], $json["description"], (int) $json["price"]);

            $this->successJson($response);
        }
        public function editAction() {

        }
    }